<template>
    <div id='' class=''>
        <i-form ref="buttonForm" :config="configButton" style="margin-top: -62px;">
            <template #gzttb="rowData">
                <i-icon-select v-model="value" />
            </template>
        </i-form>
    </div>
</template>
<script>
import { configButton } from './form_config'
import { mapState, mapActions } from 'vuex'
export default {
    name: '',
    props: ['isInit'],
    data() {
        this.cb = icu.util.deepClone(configButton)
        return {
            configButton: this.cb,
            value: ''
        };
    },
    components: {},
    computed: {
        ...mapState('extend/sysMenu', ['$row'])
    },
    beforeMount() { },
    mounted() {
        if (this.isInit) {
            this.getUpMenuList(null);
        }
        this.getToMenuList();
    },
    methods: {
        reset() {
            this.$refs.buttonForm.reset('buttonForm')
            if (this.isInit) {
                this.getUpMenuList(null);
            }
        },
        setUpMenu() {
            this.$nextTick(() => {
                this.$refs.buttonForm.setData({
                    pid: this.$row.pid == null ? '0' : this.$row.id,
                    subsystemId: this.$row.subsystemId
                })
            })
        },
        init(data) {
            this.$refs.buttonForm.setData(data)
            this.getUpMenuList(data.id);
        },
        getForm(cb) {
            let formData = {}
            this.$refs.buttonForm.submit('buttonForm', (res) => {
                let returnObj = {
                    name: res.name,
                    pid: res.pid,
                    subsystemId: res.subsystemId,
                    sort: res.sort,
                    permissions: res.permissions,
                    remarks: res.remarks,
                    id: res.id ? res.id : ''
                }
                formData = returnObj
            })
            return formData
        },

        getToMenuList() {
            this.$http.$get('subsystemList', { params: {} }).then(res => {
                if (res.code == 200) {
                    for (let i = 0; i < res.data.length; i++) {
                        const element = res.data[i];
                        element['label'] = element.title
                    }
                    for (let i = 0; i < this.configButton.form.length; i++) {
                        const element = this.configButton.form[i];
                        if (element.key == 'subsystemId') {
                            element.option = res.data
                        }
                    }
                    return
                }
                this.$Message.error(res.msg)
            })
        },
        getUpMenuList(id) {
            this.$http.$get('topTreeList', { params: {} }).then(res => {
                if (res.code == 200) {
                    for (let i = 0; i < this.configButton.form.length; i++) {
                        const element = this.configButton.form[i];
                        if (element.key == 'pid') {
                            element['disabled'] = true
                            element.data = res.data
                        }
                        if(element.key == 'subsystemId'){
                            element['disabled'] = true
                        }
                    }
                    return
                }
                this.$Message.error(res.msg)
            })
        },
    },
    watch: {}
}
</script>
<style lang='less' scoped>
</style>